<script>
import wechat from '@/utils/wechat'
import { createWeixinJsapiSignature } from '@/api/user'
import {apiConfig} from '@/utils/apiConfig'
export default {
	onLaunch: function () {
		console.log('App Launch')

		// 设置uView全局配置
		uni.$u.setConfig({
			// 修改主题色
			theme: {
				primary: '#4080ff',
				warning: '#ff9900',
				success: '#19be6b',
				error: '#fa3534',
				info: '#909399'
			}
		})
	},
	onShow: async function () {
		console.log('App Show')
		await this.initJSSDK()
		await this.setShareInfo()
	},
	onHide: function () {
		console.log('App Hide')
	},
	methods: {
		async initJSSDK() {
			console.log('initJSSDK')
			const jssdkConfig = await this.getJSSDKConfig()
			await wechat.initJSSDK(jssdkConfig)
		},
		async getJSSDKConfig() {
			console.log('getJSSDKConfig')
			const currentUrl = window.location.href.split('#')[0]
			const res = await createWeixinJsapiSignature({ url: currentUrl })
			return res.data.data
		},
		async setShareInfo() {
			console.log('setShareInfo')
			const shareData = {
				title: '汇信签',
				desc: '专业的借款合同管理系统，安全可靠的借贷服务平台',
				link: window.location.href,
				imgUrl: apiConfig.webUrl+'/static/share.jpeg' // 使用完整URL
			}
			console.log('shareData', shareData)
			try {
				await wechat.setShareData(shareData)
				console.log('分享信息设置成功')
			} catch (error) {
				console.error('分享信息设置失败:', error)
			}
		},
	}
}
</script>

<style lang="scss">
/*每个页面公共css */
@import "@/uni_modules/uview-ui/index.scss";

/* 美化tabBar样式 */
.uni-tabbar {
	box-shadow: 0 -1px 5px rgba(0, 0, 0, 0.05);
}

.uni-tabbar__item {
	padding: 8px 0;
}

.uni-tabbar__icon {
	margin-bottom: 5px;
}

.uni-tabbar__label {
	font-weight: 500;
	line-height: 1.2;
}

.uni-tabbar__item.uni-tabbar__item--active .uni-tabbar__label {
	font-weight: bold;
	transform: scale(1.05);
	transition: all 0.2s;
}
</style>
